package com.lihao.jetpackcore.ext.lifecycle

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import me.hgj.jetpackmvvm.callback.livedata.UnPeekNotNullLiveData

/**
 * Created by lihao on 2020/5/14.
 * Describe:
 */
object KtxAppLifeObserver : LifecycleObserver {

    val isForeground = UnPeekNotNullLiveData<Boolean>()

    /**
     * 在前台
     */
    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    private fun onForeground() {
        isForeground.value = true
    }

    /**
     * 在后台
     */
    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    private fun onBackground() {
        isForeground.value = false
    }
}